package com.zr.bookcorner.fragment;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import com.zh.baselibrary.base.BaseFragment;
import com.zh.baselibrary.base.BasePresenter;
import com.zr.bookcorner.BookApplication;
import com.zr.bookcorner.R;
import com.zr.bookcorner.view.RoundBackgroundColorSpan;

/**
 * @author EnzoChan
 * @create 2019/3/17
 * @desc: 开柜借还书
 */
public class BorrowReturnFragment extends BaseFragment {

    private int buttonCount = 3;
    @Override
    protected int getLayoutId() {
        if (BookApplication.isBig()) {
            buttonCount = 16;
            return R.layout.fragment_borrow_return_big;
        }
        return R.layout.fragment_borrow_return;
    }

    @Override
    protected void init() {
         for(int i = 1;i<=buttonCount;i++){
             TextView textView = cacheView.findViewById(getId(("btn_cabinet"+i)));
             textView.setOnClickListener((View.OnClickListener) getActivity());
             SpannableStringBuilder style = new SpannableStringBuilder(textView.getText().toString());
             style.setSpan(new RoundBackgroundColorSpan(Color.parseColor("#004F80"),Color.WHITE),0,2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             textView.setText(style);
         }
        if(BookApplication.isMini()){
            TextView textView = cacheView.findViewById(R.id.btn_cabinet1);
            TextView textView2 = cacheView.findViewById(R.id.btn_cabinet2);
            TextView textView3 = cacheView.findViewById(R.id.btn_cabinet3);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
            textView2.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
            textView3.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
        }
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    private int getId(String resName) {
        return getResources().getIdentifier(resName, "id",getContext().getPackageName());
    }

}
